package com.koron.order.risk.riskDuty.controller;


import com.github.pagehelper.PageInfo;
import com.koron.bean.base.Response;
import com.koron.bean.query.PageQuery;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.order.risk.riskDuty.bean.dto.LineRiskDutyDTO;
import com.koron.order.risk.riskDuty.bean.query.LineRiskDutyQuery;
import com.koron.order.risk.riskDuty.bean.vo.LineRiskDutyVO;
import com.koron.order.risk.riskDuty.service.LineRiskDutyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 风险看护值守单(LineRiskDuty)表控制层
 *
 * @author jzp
 * @since 2022-12-22 16:41:53
 */
@Api(tags = "风险看护值守单接口")
@RestController
@RequestMapping("lineRiskDuty")
public class LineRiskDutyController {
    /**
     * 服务对象
     */
    @Autowired
    private LineRiskDutyService lineRiskDutyService;

    private String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value = "根据id查询")
    @GetMapping
    public Response<LineRiskDutyVO> selectOne(@RequestParam String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), lineRiskDutyService, "getVoById", LineRiskDutyVO.class, id));
    }

    @ApiOperation(value = "分页查询")
    @GetMapping("page")
    public Response<PageInfo<LineRiskDutyVO>> page(PageQuery pageQuery, LineRiskDutyQuery query) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), lineRiskDutyService, "page", PageInfo.class, pageQuery, query));
    }

    @ApiOperation(value = "保存")
    @PostMapping("save")
    public Response<LineRiskDutyDTO> save(@RequestBody LineRiskDutyDTO lineRiskDutyDTO) {
        ADOConnection.runTask(getCurrDs(), lineRiskDutyService, "saveDto", Boolean.class, lineRiskDutyDTO);
        return Response.ok(lineRiskDutyDTO);
    }

    @ApiOperation(value = "结束值守")
    @PutMapping("end")
    public Response<String> end(String id) {
        ADOConnection.runTask(getCurrDs(), lineRiskDutyService, "end", Boolean.class, id);
        return Response.ok();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("delete")
    public Response delete(@RequestParam String id) {
        ADOConnection.runTask(getCurrDs(), lineRiskDutyService, "deleteById", Boolean.class, id);
        return Response.ok();
    }
}

